exportBarHeight = 0;
iconTableHeight = 0;

function dyniframesize() {
	var resultForm = document.getElementById('resultForm');
	var reportContentDiv = document.getElementById('reportContentDiv');
	var trs = dojo.query('tr');
	dojo.forEach(trs, function(tr) {
		if(tr.oriHeight!=undefined){
			tr.style.height = tr.oriHeight;
		}
	});
	
	var datavizCharts=dojo.query('div.dataviz_class');
	dojo.forEach(datavizCharts, function(div) {
		div.style.height="0px";
	});
	
	var divHeight = resultForm.offsetHeight;
	if (divHeight >= 0) {
//		reportContentDiv.style.height = divHeight + "px";
	} else {
		reportContentDiv.style.height = "1px";
	}
	if(!!!mobileFitPage){
		var reportTable = document.getElementById('reportContent');
		var height = resultForm.offsetHeight - iconTableHeight - 45;
		if (height >= 0) {
			reportTable.style.height = height + "px";
		} else {
			reportTable.style.height = "1px";
		}
		
		// 当高度过小显示不下内容时，dataTable会自动撑开，导致高度大于reportTable，此时需要重新设置外层的高度。
		setTimeout(function() {
			var dataTable = document.getElementById('dataTable');
			if (dataTable.scrollHeight > height) {
				reportTable.style.height = dataTable.scrollHeight + "px";
			}
		});
	}
	
	// 解决IE和Chrome下高度不自适应问题
	if (dojo.isIE || dojo.isChrome) {
		// 获取所有FusionCharts图表、地图的外层div节点
		var divs = dojo.query('div[id^=FusionChart]');
		dojo.forEach(divs, function(div) {
			// 先设成1px，让父节点（td）的高度有机会变小
			div.style.height = "1px";
		});
		// 不要把这个循环和上一个合并！
		dojo.forEach(divs, function(div) {
			div.style.height = div.parentNode.clientHeight + "px";
		});
	}

	// if (dojo.isIE) {
	// 仪表盘自适应问题
	var rfcs = dojo
			.query('span[id^=RawFusionChartsMeter],span[id^=FusionChartmeter]');
	dojo.forEach(rfcs, function(fc) {
		var div = fc.parentNode;
		div.style.height = "1px";
	});
	dojo.forEach(rfcs, function(fc) {
		var div = fc.parentNode;
		div.style.height = div.parentNode.clientHeight + "px";
	});
   if(!mobileFitPage){
	   dojo.forEach(trs, function(tr) {
			var height= tr.clientHeight + "px";
			if(tr.oriHeight===undefined){
				tr.oriHeight=tr.style.height;
			}
			tr.style.height = height;
//		    window.setTimeout(resizeDiv(div),10)
		});
   }
	
	
	dojo.forEach(datavizCharts, function(div) {//移动端兼容性问题，不要去掉
		div.style.height=div.parentNode.clientHeight + "px";
	});
	window.setTimeout(function(){
		dojo.forEach(datavizCharts, function(div) {
			div.style.height=div.parentNode.clientHeight + "px";
		});
	},100);
	
	function resizeDiv(div){
		return function(){
			div.style.height = div.parentNode.clientHeight + "px";
		}
	}
}

function fitPageOnLoad() {
	var exportBar = document.getElementById('exportBar');
	if (exportBar) 
		exportBarHeight = exportBar.clientHeight;
	var iconTable = document.getElementById('iconTable');
	if (iconTable)
		iconTableHeight = iconTable.clientHeight;
	dyniframesize();
	
	/*// 解决JS渲染高度被设为1px问题
	if (FusionCharts&&FusionCharts.getCurrentRenderer() == 'javascript') {
		var fcs = dojo.query('span[id^=chartobject-],span[id^=FusionMap]');
		dojo.forEach(fcs, function(fc) {
			fc.style.height = "100%";
		});
	}
	
	// 仪表盘自适应问题
	var rfcs = dojo.query('span[id^=RawFusionChartsMeter],span[id^=FusionChartmeter]');
	dojo.forEach(rfcs, function(fc) {
		fc.style.height = "100%";
	});*/
	window.onresize = _.debounce(dyniframesize, 300);
	if(mobileFitPage){
		 mobileDyniframesize(true);
		 window.addEventListener("orientationchange", _.debounce(mobileDyniframesize, 300), false);
	}
}
function mobileDyniframesize(initFlag){
    var orientation = (window.innerWidth > window.innerHeight) ? "landscape" : "portrait";
    var widgetContainerArray = $('.dataTable');
    if (widgetContainerArray == null){
    	return;
    }
//    if(initFlag===true&&orientation === 'portrait'){
//    	return;
//    }
    //竖屏
    if (orientation === 'portrait') {
    	for(var i=0;i<widgetContainerArray.length;i++){
    		var widgetContainer=$(widgetContainerArray[i]);
    		widgetContainer.css("width", "100%");
    		widgetContainer.parent().css("overflow","auto");
    		var widgetDomArray =widgetContainer.children();
    		for (var j = 0; j < widgetDomArray.length; j++) {
                $(widgetDomArray[j]).css("width", "100%");
                $(widgetDomArray[j]).css("height", "50%");
                $(widgetDomArray[j]).css("display","block");
            }
    	}
        
    } else {
    	for(var i=0;i<widgetContainerArray.length;i++){
    		var widgetContainer=$(widgetContainerArray[i]);
    		var width=widgetContainer.parent().width();
    		var widgetDomArray =widgetContainer.children();
    		widgetContainer.css("width", width*widgetDomArray.length+"px");
    		widgetContainer.parent().css("overflow","auto");
    		for (var j = 0; j < widgetDomArray.length; j++) {
                $(widgetDomArray[j]).css("width", width+"px");
                $(widgetDomArray[j]).css("height", "100%");
                $(widgetDomArray[j]).css("display","inline-block");
            }
    	}
    }
}

if (fitPage||mobileFitPage) {
	dojo.addOnLoad(fitPageOnLoad);
}

